package cn.oyjg.sys.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.oyjg.base.controller.BaseController;
import cn.oyjg.base.util.Constants;
import cn.oyjg.base.util.ResultFlag;
import cn.oyjg.sys.entity.User;
import cn.oyjg.sys.service.IUserService;

/**
 * 后台管理员控制
 * @author k11ha_000
 *
 */
@Controller
@RequestMapping(value="/sys/")
public class UserController extends BaseController {
	
	Logger log=Logger.getLogger(UserController.class);

	
	@RequestMapping(value="login",method=RequestMethod.GET)
	public String login(){
		return "login";
	}
	
	@RequestMapping(value="toindex",method=RequestMethod.GET)
	public String toindex(){
		return "main";
	}
	
	@RequestMapping(value="userList")
	public String userList(User userPage){
		List<User> lst=uSvr.selectListByPage(userPage);
		map.put("ulst", lst);
		map.put("page", userPage);
		return "userList";
	}
	
	@RequestMapping(value="getPage",method=RequestMethod.GET)
	public String getPage(@RequestParam String pageName){
		return pageName;
	}
	
	@RequestMapping(value = "login",method=RequestMethod.POST)
	@ResponseBody
	public ResultFlag login(@RequestParam String uname, @RequestParam String pwd) {
		ResultFlag rf=new ResultFlag();
		try {
			User u = uSvr.login(uname, pwd,1);
			if (u != null) {
				rf.setFlag(true);
				session.setAttribute(Constants.user, u);
			} else {
				rf.setFlag(false);
				rf.setMsg("用户名或密码错误");
			}
		} catch (Exception err) {
			log.error("系统异常:"+err.getMessage());
			rf.setFlag(false);
			rf.setMsg("系统异");
		}
		return rf;
	}

	@Resource(name = "userService")
	private IUserService uSvr;
}
